import java.util.Random;

public class RockPaperScissorsGame {

    private static final int TOTAL_ROUNDS = 100; // 设置对战总轮数


    public static void main(String[] args) {

            System.out.println("开始自动启动电脑猜拳");
            System.out.println("第"+TOTAL_ROUNDS+"轮对战.....\n");

        for (int i = 1; i <= TOTAL_ROUNDS; i++) {

            int computerChoice = new Random().nextInt(3) + 1;
            int computerChoice2 = new Random().nextInt(3) + 1;
            int computerChoice3 = new Random().nextInt(3) + 1;

            System.out.println("computerChoice1==================>>>>>>>>>>>>"+computerChoice);
            System.out.println("computerChoice2==================>>>>>>>>>>>>"+computerChoice2);
            System.out.println("computerChoice3==================>>>>>>>>>>>>"+computerChoice3);

            UserInfo us = new UserInfo("电脑1",0,computerChoice);
            UserInfo us2 = new UserInfo("电脑2",0,computerChoice2);
            UserInfo us3 = new UserInfo("电脑3",0,computerChoice3);

            int result = us.setRule(us,us2,us3);
            System.out.println("result==================>>>>>>>>>>>>"+result);
            String resultStr = "";
            if(result == 1){
                us.victoriesNum++;
                resultStr = us.name+" 获胜了";
            }else if(result == 2){
                us2.victoriesNum++;
                resultStr = us2.name+" 获胜了";
            }else if(result == 3){
                resultStr = us3.name+" 获胜了";
            }else{
                resultStr = "平局";
            }

            System.out.println("第"+i+"轮对战结果："
                    +us.name+" 出示了："+us.CockroachShell(computerChoice)+
                    " vs "
                    +us2.name+" "+us2.CockroachShell(computerChoice2)+
                    " vs "
                    +us2.name+" "+us3.CockroachShell(computerChoice3)+"结果："+resultStr);


//            int result = us.setRule(us,us2);
//            String resultStr = "";
//            if(result == 1){
//                us.victoriesNum++;
//                resultStr = us.name+" 获胜了";
//            }else if(result == -1){
//                us2.victoriesNum++;
//                resultStr = us2.name+" 获胜了";
//            }else{
//                resultStr = "平局";
//            }
//
//            System.out.println("第"+i+"轮对战结果："+us.name+" 出示了："+us.CockroachShell(computerChoice)+" vs "+us2.name+" "+us2.CockroachShell(computerChoice2)+"结果："+resultStr);
        }


    }


}


class UserInfo{
    String name;
    int victoriesNum;
    int defeatsNum;
//  姓名   获胜数量  出示
    public UserInfo(String name,int victoriesNum,int defeatsNum){
        this.name = name;
        this.victoriesNum = victoriesNum;
        this.defeatsNum = defeatsNum;
//        System.out.println(name+" 获胜了 "+victoriesNum+"次，出示了"+ CockroachShell(defeatsNum));
    }

    public String CockroachShell(int choice){
        switch (choice){
            case 1:
                return "石头";
            case 2:
                return "剪刀";
            default:
                return "布";
        }
    }

//    public
    public  int setRule(UserInfo us,UserInfo us2){
        if(us.defeatsNum == us2.defeatsNum){
            return 0;
        }

        if(
                us.defeatsNum == 1 && us2.defeatsNum == 2 ||
                        us.defeatsNum == 2 && us2.defeatsNum == 3||
                        us.defeatsNum == 3 && us2.defeatsNum == 1
        ){
            return 1;
        }else{
            return -1;
        }


    }


    public int setRule(UserInfo u1,UserInfo u2,UserInfo u3){
        if(u1.defeatsNum != u2.defeatsNum|| u1.defeatsNum != u3.defeatsNum|| u2.defeatsNum != u3.defeatsNum ){
            return 0;
        }

        if(u1.defeatsNum == 1 && u2.defeatsNum == u3.defeatsNum&& u3.defeatsNum== 2
                ||u1.defeatsNum == 2 && u2.defeatsNum == u3.defeatsNum&& u3.defeatsNum== 3
                ||u1.defeatsNum == 3 && u2.defeatsNum == u3.defeatsNum&& u3.defeatsNum== 1){
            return 1;
        }else if(u2.defeatsNum == 1 && u1.defeatsNum == u3.defeatsNum&& u3.defeatsNum== 2
                ||u2.defeatsNum == 2 && u1.defeatsNum == u3.defeatsNum&& u3.defeatsNum== 3
                ||u2.defeatsNum == 3 && u1.defeatsNum == u3.defeatsNum&& u3.defeatsNum== 1){
            return 2;
        } else if(u3.defeatsNum == 1 && u1.defeatsNum == u2.defeatsNum&& u1.defeatsNum== 2
                ||u3.defeatsNum == 2 && u1.defeatsNum == u2.defeatsNum&& u1.defeatsNum== 3
                ||u3.defeatsNum == 3 && u1.defeatsNum == u2.defeatsNum&& u1.defeatsNum== 1){
            return 3;
        }else{
            return 0;
        }
    }



}